package com.kiloai.digcust.mvp.model;

import android.content.Context;

import com.google.gson.reflect.TypeToken;
import com.kiloai.base.entity.Code;
import com.kiloai.base.okgohttp.AppApis;
import com.kiloai.base.okgohttp.HttpHandler;
import com.kiloai.base.okgohttp.callback.JsonDialogCallback;
import com.kiloai.base.okgohttp.callback.RequestCallback;
import com.kiloai.base.okgohttp.entity.Data;
import com.lzy.okgo.model.Response;

import java.lang.reflect.Type;

/**
 *
 * Created by david on 2018/8/20.
 */

public class CodeModel {

    /**
     * 获取短信验证码
     * @param context
     * @param team
     * @param name
     * @param callback
     */
    public static void getCode(Context context, String team, String name, final RequestCallback<Code> callback) {
        String url = AppApis.code() + "?team=" + team + "&name=" + name;
        Type type = new TypeToken<Data<Code>>() {
        }.getType();
        HttpHandler.getInstance(context.getClass().getSimpleName()).getRequest(url, new JsonDialogCallback<Code>(context, type) {
            @Override
            public void onSuccess(Response<Code> response) {
                Code code = response.body();
                if (code != null) {
                    callback.onSuccess(code);
                }
            }
        });
    }
}
